/**
 * @(#) BizTripListProxy.as
 *
 * @date		2009. 04. 6.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	 국경일 및 휴일정보 Proxy - Proxy
 * 				월별 국경일 및 휴일 정보를 가져온다.
 */
package com.skt.common_hr.biztrip.model
{
	import com.skt.common_hr.biztrip.BizTripFacade;
	import com.skt.common_hr.biztrip.model.vo.BizTripListVO;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.wcl.dataloader.*;
	import com.wcl.utils.DateUtil;
	import com.wcl.utils.StringUtil;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class BizTripListProxy extends CommonProxy
	{
		public static const NAME:String = "BizTripListProxy";
		
		public var bizTripList:ArrayCollection;
		public var url01:String = "";
		public var url02:String = "";
		
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function BizTripListProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번,대상월
		 * @return void
		 */
		public function load(pernr:String, begin:Date, end:Date):void
		{
			var param:Object = new Object();
			param["I_PERNR"] = pernr;
			param["I_BEGDA"] = DateUtil.toBasicString(begin);		
			param["I_ENDDA"] = DateUtil.toBasicString(end);		
			loadData("Z_HR_T001", param, result, fault);
		}
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(event.result["RETCODE"]==0) {  
				bizTripList = parseList(event.result.RTAB);
				url01 = event.result["O_URL01"];
				url02 = event.result["O_URL02"];
				facade.sendNotification(BizTripFacade.LOAD_BIZTRIP_LIST_COMPLETE, this);
			}
			else {
				//trace( "failed to 출장 리스트: (" +event.result["RETCODE"] + ") "+event.result["RETTEXT"]);
				facade.sendNotification(BizTripFacade.LOAD_BIZTRIP_LIST_FAILED, this);
			}
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			//trace("Fault message in 출장리스트: " + event.fault.faultString);
			facade.sendNotification(BizTripFacade.LOAD_BIZTRIP_LIST_FAILED, this);
		}
		
		
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 제증명서 종류 Code list
		 */
		private function parseList(srcArr:ArrayCollection):ArrayCollection
		{
			var list:ArrayCollection = new ArrayCollection;
			for each(var rec:Object in srcArr) 
			{
				var vo:BizTripListVO = new BizTripListVO();
				vo.GWAREKEY01	= rec["GWAREKEY01"];
				vo.GWAREKEY02	= rec["GWAREKEY02"];
				vo.TRSTATUS		= rec["TRSTATUS"];
				vo.TRSTATX		= rec["TRSTATX"];
				vo.TRTYPE		= rec["TRTYPE"];
				vo.TTEXT		= rec["TTEXT"];
				vo.TRREAS		= rec["TRREAS"];
				vo.TRRETX		= rec["TRRETX"];
				vo.BEGDA		= DateUtil.stringToDateTime(rec["BEGDA"]);
				vo.ENDDA		= DateUtil.stringToDateTime(rec["ENDDA"]);
				vo.TRTITLE		= rec["TRTITLE"];
				vo.BSTATUS		= rec["BSTATUS"];
				vo.BSTATX		= rec["BSTATX"];
				vo.BTEXT		= rec["BTEXT"];
				vo.MNUM			= rec["MNUM"];
				vo.TRPAYC		= rec["TRPAYC"];
				vo.TRCONV		= rec["TRCONV"];
				vo.IPERNR		= StringUtil.trimFront(rec["IPERNR"], "0");
				vo.TRTEXT		= rec["TRTEXT"];
				list.addItem(vo);
			}
			return list;
		}
		
	}
}